<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>计算属性的setter和getter</title>
</head>
<body>
<div id="app">
  <h2>{{fullName}}</h2>
</div>
<script src="../js/vue.js"></script>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      firstName: 'Kobe',
      lastName: 'Bryant'
    },
    computed: {
      // 计算属性getter的简写
      /*fullName:function () {
        return this.firstName + ' ' + this.lastName;
      }*/

      // 计算属性的完整写法,一般情况下计算属性都是只读，所以大多数是只用get，就可以简写成以上写法
      fullName: {
        get: function () {
          return this.firstName + ' ' + this.lastName;
        },
        set: function (newValue) {
          console.log(newValue);
          const name = newValue.split(' ');
          this.firstName = name[0];
          this.lastName = name[1];
        }

      }


    }
  });
</script>
</body>
</html>
